home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / SOURCES / WSCENE.C < prev    next >
C/C++ Source or Header  |  1992-03-25  |  5KB  |  190 lines

  1. /*
  2.  *  MS Windows - dependent scene code
  3.  */
  4.  
  5. #include <InterViews\itable.h>
  6. #include <InterViews\bitmap.h>
  7. #include <InterViews\canvas.h>
  8. #include <InterViews\cursor.h>
  9. #include <InterViews\interactor.h>
  10. #include <InterViews\scene.h>
  11. #include <InterViews\shape.h>
  12. #include <InterViews\world.h>
  13. #include <InterViews\X11\worldrep.h>
  14. #include <InterViews\X11\windata.h>
  15. #include <string.h>
  16.  
  17. static void DefaultShape (int w, int h, int& nw, int& nh) {
  18.     nw = (w == 0) ? round(2*inch) : w;
  19.     nh = (h == 0) ? round(2*inch) : h;
  20. }
  21.  
  22. void Scene::UserPlace (Interactor* i, int w, int h) {
  23.     int width, height;
  24.  
  25.     DefaultShape(w, h, width, height);
  26.     MakeWindow(i, 0, 0, width, height);
  27.     if (i->GetInteractorType()  == IconInteractor) {
  28.     Assign(i, 0, 0, width, height);
  29.     } else {
  30.         DoMap(i, width, height);
  31.     }
  32. }
  33.  
  34. void Scene::Place (Interactor* i, Coord l, Coord b, Coord r, Coord t, boolean map) {
  35.     Coord newtop = ymax - t;
  36.     int width, height;
  37.  
  38.     DefaultShape(r - l + 1, t - b + 1, width, height);
  39.     MakeWindow(i, l, newtop, width, height);
  40.     Assign(i, l, b, width, height);
  41.     if (map && i->GetInteractorType() != IconInteractor) {
  42.     if (i->GetStartIconic() == false) {
  43.         Map(i);
  44.     } else {
  45.         Interactor* icon_ia = i->GetIconInteractor();
  46.         if (icon_ia != nil) {
  47.             Canvas* dummy_canvas = nil;
  48.         Canvas*& icon_canvas = icon_ia ? icon_ia->canvas : dummy_canvas;
  49.         i->PlaceIcon(icon_ia, icon_canvas);
  50.         Canvas* c;
  51.             if ((c = icon_ia->canvas) != nil) {
  52.                 ShowWindow((HWND)c->id, SW_SHOW);
  53.             }
  54.             }
  55.         }
  56.     }
  57. }
  58.  
  59. void Scene::MakeWindow (Interactor* i, Coord x, Coord y, int width, int height) {
  60.     HWND hWndParent;
  61.  
  62.     InteractorType t = i->GetInteractorType();
  63.     hWndParent = (HWND)canvas->id;
  64.     if (parent == nil) {
  65.     hWndParent = NULL;
  66.     if (t == InteriorInteractor) {
  67.         i->SetInteractorType(ToplevelInteractor);
  68.     }
  69.     } else if (t != InteriorInteractor) {
  70.     i->SetInteractorType(InteriorInteractor);
  71.     }
  72.  
  73.     int newy = y;
  74.     int newwidth = width;
  75.     int newheight = height;
  76.  
  77.     t = i->GetInteractorType();
  78.     if ((t == ApplicationInteractor) || (t == ToplevelInteractor)) {
  79.         if (newy - _world->YCaption >= 0) {
  80.         newy -= _world->YCaption;
  81.         }
  82.     newwidth += _world->XBorder*2;
  83.     newheight += _world->YBorder*2 + _world->YCaption;
  84.     }
  85.  
  86.     if (i->canvas == nil) {
  87.     LPSTR  lpclassname  = (LPSTR)i->rep->GetWndClass();
  88.     LPSTR  lpwindowname = (LPSTR)i->rep->GetWndName();
  89.     DWORD  dwStyle =  i->rep->GetWndStyle();
  90.  
  91.     HWND hWnd = CreateWindow(
  92.             lpclassname,
  93.             lpwindowname,
  94.             dwStyle,
  95.             x,
  96.             newy,
  97.             newwidth,
  98.             newheight,
  99.             hWndParent,
  100.             NULL,
  101.             _world->hinstance(),
  102.             NULL
  103.             );
  104.  
  105.     i->canvas = new Canvas((void*)hWnd);
  106.     _world->itable()->Insert((void*)hWnd, i);
  107.  
  108.     } else {
  109.     MoveWindow(
  110.         (HWND)i->canvas->id, x, newy, newwidth, newheight, TRUE
  111.     );
  112.     }
  113.     i->Listen(i->cursensor == nil ? i->input : i->cursensor);
  114. }
  115.  
  116. void Scene::Map (Interactor* i, boolean raised) {
  117.     HWND hWnd = (HWND)i->canvas->id;
  118.     if (!IsWindowVisible(hWnd)) {
  119.     ShowWindow (hWnd, SW_SHOW);
  120.     }
  121.     if (raised) {
  122.     BringWindowToTop (hWnd);
  123.     }
  124.     i->canvas->status = CanvasMapped;
  125. }
  126.  
  127. void Scene::Unmap (Interactor* i) {
  128.     HWND hWnd = (HWND)i->canvas->id;
  129.     ShowWindow(hWnd, SW_HIDE);
  130.     i->canvas->status = CanvasUnmapped;
  131.  
  132. /*    if (parent == nil && i->GetInteractorType() != PopupInteractor) {
  133.     MSG msg;
  134.     msg.hWnd = GetWorld()->Rep()->root();
  135.     msg.message = WM_CLOSEWINDOW;
  136.     SendMessage (msg.hWnd, msg.message, msg.wParam, msg.lParam);
  137.     }
  138.     ??   -) Sendmessage wartet bis bearbeitet
  139.      -) Absicht nicht klar
  140. */
  141. }
  142.  
  143. void Scene::Raise (Interactor* i) {
  144.     HWND hwnd = (HWND)i->canvas->id;
  145.     DoRaise(i);
  146.     BringWindowToTop (hwnd);
  147. }
  148.  
  149. void Scene::Lower (Interactor* i) {
  150.     DoLower(i);
  151. }
  152.  
  153. void Scene::Move (Interactor* i, Coord x, Coord y, Alignment a) {
  154.     Coord ax = x, ay = y;
  155.     DoAlign(i, a, ax, ay);
  156.     i->left = ax;
  157.     i->bottom = ay;
  158.     DoMove(i, ax, ay);
  159.     if ((i->GetInteractorType() == ToplevelInteractor) ||
  160.     (i->GetInteractorType() == ApplicationInteractor)) {
  161.     MoveWindow (
  162.         (HWND)i->canvas->id,
  163.          ax,
  164.          ymax - ay - i->ymax - _world->YCaption,
  165.          i->canvas->width + _world->XBorder*2,
  166.          i->canvas->height + _world->YBorder*2 + _world->YCaption,
  167.          TRUE
  168.     );
  169.     } else {
  170.     MoveWindow (
  171.         (HWND)i->canvas->id,
  172.          ax,
  173.          ymax - ay - i->ymax,
  174.          i->canvas->width,
  175.          i->canvas->height,
  176.          TRUE
  177.     );
  178.  
  179.     }
  180. }
  181.  
  182. void Scene::DoMap (Interactor* i, int w, int h) {
  183.     HWND hWnd = (HWND)i->canvas->id;
  184.     if (!IsWindowVisible(hWnd)) {
  185.     ShowWindow (hWnd, SW_SHOW);
  186.     }
  187.     BringWindowToTop (hWnd);
  188.     Assign(i, 0, 0, w, h);
  189.     i->canvas->status = CanvasMapped;
  190. }